﻿using HLStock.MyType;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json;
using System.Reflection;

namespace HLStock.WmsApi
{
    public class MyDefaultContractResolver : DefaultContractResolver
    {
        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            var result = base.CreateProperty(member, memberSerialization);
            var foreignAttr = member.GetCustomAttribute<MyForeignAttribute>();
            if (foreignAttr != null && !string.IsNullOrWhiteSpace(foreignAttr.LabelProp))
            {
                result.Converter = new MyRefJsonConveter(foreignAttr);
            }
            return result;
        }
    }
}